# @Time:   2021/2/5 9:33
# @Author: Zong Wei

import random
from time import sleep
from faker import Faker
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait

from ui_automation_testing.test.pageObject.loginPage import LoginPage
from ui_automation_testing.utils.logger import Logger


class TtPage(LoginPage):
    logger = Logger(__name__).get_log()
    menu = (By.XPATH, "//ul[@class='site-menu']//span[.='运输数据']")
    sub_menu = (By.XPATH, "//ul[@class='site-menu']//span[.='司机管理']")
    search_button = (By.ID, "lr-search")
    add_button = (By.ID, "lr-add")
    edit_button = (By.ID, "lr-edit")
    del_button = (By.ID, "lr-delete")
    save_button = (By.ID, "lr-save")
    check_button = (By.ID, "lr-check")

    remember_code = (By.ID, "RemberCode")
    code = (By.ID, "ProductID")
    name_cn = (By.XPATH, "//select[@id='MaterialNameC']/following::input[1]")
    name_en = (By.ID, "MaterialNameE")
    is_chemical = (By.ID, "IsNotChemicalGoods")
    is_chemical_value = (By.XPATH, "//*[@id='IsNotChemicalGoods-option']//li[3]")
    is_danger = (By.ID, "B_Danger")
    is_danger_value = (By.XPATH, "//*[@id='B_Danger-option']//li[3]")
    is_danger_chemical = (By.ID, "IsDangerChemical")
    is_danger_chemical_value = (By.XPATH, "//*[@id='IsDangerChemical-option']//li[3]")
    unno = (By.XPATH, "//select[@id='UNCode']/following::a[1]")
    unno_values = (By.XPATH, "//select[@id='UNCode']/following::tr[contains(@id,'datagrid-row-r5-2-')]")
    CFS_DangerType = (By.ID, "CFS_DangerType")
    CFS_values = (By.XPATH, "//*[@id='CFS_DangerType-option']//li[position()>1]")
    is_check = (By.ID, "IsCheckFlag")
    export_button = (By.ID, "lr-excel")
    confirm_button = (By.XPATH, "//a[.='确认']")
    first_row = (By.XPATH, "//span[.='助记码']//following::tr[1]")

    def __init__(self):
        self.driver = LoginPage().login()
        self.wait = WebDriverWait(self.driver, 10)

    def tt_home(self):
        self.logger.info("登录系统成功")
        self.wait.until(ec.element_to_be_clickable(self.menu)).click()
        sleep(1)
        self.driver.execute_script('$("#admui-navTabs").scrollTop(999)')
        self.wait.until(ec.element_to_be_clickable(self.sub_menu)).click()
        sleep(1)
        return self.driver



if __name__ == '__main__':
    pg = TtPage()
    pg.tt_home()

